﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Gamesweet : MonoBehaviour
{
    #region 甜品信息
    private int x; //行
    public int X
    {
        get => x;
        set
        {
            if(Can_move())
            {
                x = value; 
            }
        }
    }
    public int Y {
        get => y;
        set
        {
            if(Can_move())
            {
                y = value;
            }
        }
    }
    public GameManager.SweetsType Type1 { get => Type; set => Type = value; }
    public sweetmove Canmove { get => canmove; set => canmove = value; }//移动糖果 
    public ColorSweet ColorComponent { get => colorComponent; set => colorComponent = value; }
    public ClearSweet ClearComponent { get => clearComponent; set => clearComponent = value; }

    private int y;//列
    private GameManager.SweetsType Type;//种类
    #endregion 甜品信息
    public GameManager gamemanager;
    private void Awake()
    {
        canmove = GetComponent<sweetmove>();//根据能不能找到这个脚本判断是不是可以移动
        colorComponent = GetComponent<ColorSweet>();
        clearComponent = GetComponent<ClearSweet>();
    }
    //是否可以移动
    private sweetmove canmove;
    //是否可以变色 
    private ColorSweet colorComponent;
    private ClearSweet clearComponent;//清除
    public bool Can_move()
    {
        return canmove !=null;//为空不可以动
    }
    public bool Can_color()
    {
        return colorComponent != null;//为空不可以变色
    }
    public bool Can_clear()
    {
        return clearComponent != null;
    }
    //实例化函数
    public void Init(int _x,int _y,GameManager gameManager,GameManager.SweetsType _type)
    {
        x = _x;
        y = _y;
        gamemanager = gameManager;
        Type = _type;
    }

    private void OnMouseEnter()
    {
        gamemanager.EnterSweet(this);
    }
    private void OnMouseUp()
    {
        gamemanager.ReleaseSweet(this);
    }
    private void OnMouseDown()
    {
        gamemanager.PressSweet(this); 
    }
}
